package com.haobao.telephonerecord.utils;

import static android.service.controls.ControlsProviderService.TAG;

import android.content.Context;
import android.os.Build;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.text.TextUtils;

import androidx.annotation.RequiresApi;

import java.util.List;

/**
 * Created by 大草原水 on 2022/1/19
 */
public class PhoneUtils {

    /**
     * 这一块首先获取手机中所有sim卡 PhoneAccountHandle 每一个 PhoneAccountHandle 表示一个sim卡, 然后根据 slotId 判断所指定的sim卡并返回此 PhoneAccountHandle (这里5.1 和 6.0需要区分对待)
     */
   /* @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    private PhoneAccountHandle getPhoneAccountHandle(int slotId, Context mContext) {
        TelecomManager tm = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
        //PhoneAccountHandle api>5.1
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            List<PhoneAccountHandle> handles = (List<PhoneAccountHandle>) ReflectUtil.invokeMethod(tm, "getCallCapablePhoneAccounts");
            SubscriptionManager sm = SubscriptionManager.from(mContext);
            if (handles != null) {
                for (PhoneAccountHandle handle : handles) {
                    SubscriptionInfo info = sm.getActiveSubscriptionInfoForSimSlotIndex(slotId);
                    if (info != null) {
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                            if (TextUtils.equals(info.getIccId(), handle.getId())) {
                                // LogUtil.d(TAG, "getPhoneAccountHandle for slot" + slotId + " " + handle);
                                return handle;
                            }
                        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
                            if (TextUtils.equals(info.getSubscriptionId() + "", handle.getId())) {
                                // LogUtil.d(TAG, "getPhoneAccountHandle for slot" + slotId + " " + handle);
                                return handle;
                            }
                        }
                    }
                }
            }
        }
        return null;
    }*/
}
